<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>03_JS数据类型</title>
</head>
<body>
<script>
    //数据类型=原始类型+引用类型
    //原始类型：number,string,boolean,null,undefined
    var a = 10;
    var b = 3.14;
    console.log(a,typeof a);
    console.log(b,typeof b);
    var c = 'hello';
    console.log(c,typeof c);
    var d = "world";
    console.log(d,typeof d);
    var e = true;
    console.log(e,typeof e);
    var f = null;
    console.log(f,typeof f);
    var g; //声明了变量，但未赋值，未定义型
    console.log(g,typeof g);

    //引用类型
    let obj={};
    console.log(obj,typeof obj);
    obj.name="张三";
    obj.age=18;
    console.log(obj);
    console.log(obj.name,obj.age);

    let obj2={
        name:"张三",
        age:18,
    }
    console.log(obj2);
    obj2.like="篮球";
    console.log(obj2);
    console.log(obj2.name,obj2.age);


    //数组
    let arr = [1,3.14,'hello',true];
    console.log(arr,typeof arr);
    console.log(arr[0],arr[1],arr[2],arr[3]);
    console.log(arr[99]);   //undefined

    //Number():将其他类型转换为数字类型
    console.log(Number('123'));
    console.log(Number('123.456'));
    console.log(Number('123.456.789'));  //NaN
    console.log(Number('123a'));  //NaN
    console.log(Number(true));  //1
    console.log(Number(false));  //0
    console.log(Number(null));  //0
    console.log(Number(undefined));  //NaN

    //Boolean():将其他类型转换为布尔类型
    console.log(Boolean(0));  //false
    console.log(Boolean(''));  //false
    console.log(Boolean(null));  //false
    console.log(Boolean(undefined));  //false
    console.log(Boolean(NaN));  //false
    console.log('0 null undefined NaN 空字符串 都转换为false');
    console.log(Boolean(123));  //true
    console.log(Boolean('hello'));  //true
    console.log(Boolean('false'));  //true
    console.log(Boolean('true'));  //true
    console.log(Boolean(' '));  //true
</script>
</body>
</html>